<template>
    <section>
        <!--搜索工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px; ">
            <el-form :inline="true" :model="filters" ref="filters" label-width="80px">
                <el-form-item prop="condition.year">
                    <el-select
                            placeholder="年份"
                            v-model="filters.condition.year"
                            size="18px">
                        <el-option
                                v-for="item in options.years"
                                :key="item"
                                :label="item"
                                :value="item"/>
                    </el-select>
                </el-form-item>
                <el-form-item prop="condition.check_unit">
                    <el-input
                            placeholder="院校名称"
                            v-model.trim="filters.condition.check_unit"/>
                </el-form-item>

                <el-form-item prop="condition.times" >
                    <el-select placeholder="整改阶段"  v-model="filters.condition.times">
                        <el-option :label="'全部'" :value="'all'"/>
                        <el-option v-for="(val,key) of options.times" :key='key' :label="val" :value="key"/>
                    </el-select>
                </el-form-item>

                 <el-form-item prop="condition.status">
               
                    <el-select placeholder="整改状态"    v-model="filters.condition.status">
                         <el-option :label="'全部'" :value="'all'"/>
                         <el-option :label="'待高校创建整改报告'" :value="'1'"/>
                         <el-option :label="'待高校提交报告'" :value="'11'"/>
                        <el-option v-for="(val,key) of options.status" :key='key' :label="val" :value="key"/>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search">搜索</el-button>
                    <el-button @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </el-col>
        <!--搜索结果表格-->
        <el-table
                :data="listData"
                stripe
                v-loading="listLoading"
                style="width: 100%;">
            <el-table-column
                    align="center"
                    label="序号"
                    width="80px"
                    type="index">
            </el-table-column>
            <el-table-column
                    align="right"  width="80" >
                <template slot-scope="scope">
                    <img v-if="scope.row.college_logo" style="float:right; width:50px; height:50px;" :src="scope.row.college_logo" class="avatar">
                </template>
            </el-table-column>
            <el-table-column
                    label="高校名称"
                    prop="college_name">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="更新时间"
                    prop="date">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="完成比例"
                    prop="update_modified">
                <template slot-scope="scope">
                    {{ scope.row.total_fix_bugs + '/' + scope.row.total_bugs }}
                </template>
            </el-table-column>

            <el-table-column
                    align="center"
                    label="整改阶段"
                    prop="times">
                <template slot-scope="{row}">
                  
                   {{options.times[row.times]}}
                   
                </template>
            </el-table-column>
<el-table-column
                    align="center"
                    label="整改截止日期"
                    prop="end_date">
                      <template slot-scope="{row}">
                          <span>{{row.end_date.substr(0,10)}}</span>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    label="整改状态"
                    :formatter="statusFormat"
                    prop="corrective_status">
            </el-table-column>
            <el-table-column label="操作" align="left" width="200">
                <template slot-scope="scope">
                    <el-button
                            type="primary" plain
                            @click="checkDetail(scope.row)">详情
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--分页-->
        <!-- <el-col :span="24" class="toolbar">
            <el-pagination
                    style="text-align: center;"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :page-size="filters.page_size"
                    background
                    :current-page="filters.page_current"
                    layout="prev,pager,next,sizes,total"
                    :total="filters.total">
            </el-pagination>
        </el-col> -->

          <!-- 因为前端处理去重，分页对不上了，所以暂时不分页了查询全部，以后可以考虑前端去重后分页 -->

    </section>
</template>

<script>
    import dict from '../../common/js/dict';
    import { getAdminCorrectedProgress } from '../../api/corrected_api'

    export default {
         name:'eduCorrectedPregress',
        data() {
            return {
                listLoading: false,
                listData: null,
                filters: {
                    condition:{
                        year: '',
                        check_unit: '',
                        times:'',
                        status:''
                        // check_report_notice_status:'-2'
                    },
                    order_column: 'gmt_modified',
                    order_by: 'desc',
                    page_size: 300,
                    total: 0,
                    page_current: 1
                },
                options: {
                    years: [],
                    records_status: dict.records_status,
                    times:dict.step_options,
                    status:dict.corrected_status_options
                },
                dict:dict
            }
        },

        created() {
            this.initYears()
            this.getListData()
        },
        methods: {
            search() {
                this.getListData()
            },
            reset() {
                this.$refs['filters'].resetFields();
                this.filters.page_current = 1;
                this.getListData();
            },
            handleSizeChange(val) {
                this.filters.page_current = 1;
                this.filters.page_size = val;
                this.getListData();
            },
            handleCurrentChange(val) { 
                this.filters.page_current = val;
                this.getListData();
            },
            getListData() {
                this.listLoading = true
                getAdminCorrectedProgress(this.filters).then(res => {
                     this.listLoading = false
                    if(res.status == 200){
                        
                        let tempData = JSON.parse(res.data.datas)
                        this.filters.total = tempData.total
                        this.filters.page_size = tempData.page_size
                        this.filters.page_current = tempData.page_current
                        this.listData = this.distinct(tempData.items)
                    }
                })
            },
              distinct(arr){
                let result = []
                let obj={}
                for(let item of arr){
                    if(!obj[item.college_id]){
 
                        if( !(item.corrective_status === 5 && item.times===1 && item.total_bugs !== item.total_fix_bugs) ){
                           result.push(item)
                          obj[item.college_id] = 1
                        }
                    }else{
                        let existItem = result.findIndex(i => i.college_id === item.college_id)
                        if(item.date>result[existItem].date){
                            result.splice(existItem,1,item)
                        }
                    }
                }
                return result
            },
            initYears() {
                this.currentYear = (new Date()).getFullYear();
                this.filters.condition.year = this.currentYear;
                for (let i = this.currentYear; i >= 2018; i--) {
                    this.options.years.push(i);
                }
            },
            checkDetail(data) {
                this.$router.push({path:'/edu_corrected/detail', query:{ id: data.college_id, year:data.create_date }});
            },
            statusFormat(row, column) {
                return this.dict.corrected_progress_status[row.corrective_status]
            }
        }
    }
</script>

<style scoped>
    #inspectChart {
        height: 600px;
    }

    .grid-content {
        min-height: 0px !important;
    }
</style>